﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApi001.Domain.Entity;

namespace WebApi001.Domain
{
    public class DbInitializeHelper
    {
        public static void Initialize()
        {
            using (var db = new Admin5000DbContext())
            {
                var dbExist = db.Database.EnsureCreated();

                var tempBrand = db.Brands.Any();
                if (!tempBrand)
                {
                    var brand = new Brand
                    {
                        BrandName = "杰克琼斯",
                        Description = "丹麦品牌"
                    };

                    db.Brands.Add(brand);

                    db.SaveChanges();

                    db.Products.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName="牛仔裤",
                        ShortDesc="潮流新款",
                        FullDesc="这是一个详情描述，敷衍",
                        BrandId=brand.Id
                    },
                    new Product
                    {
                        ProductName="衬衣_白色",
                        ShortDesc="宽松休闲",
                        FullDesc="这是一个详情描述，敷衍+1",
                        BrandId=brand.Id
                    },
                    });
                    db.SaveChanges();
                }

                
            }
        }
    }
}
